package com.koron.sinoprobe.web.ledger.controller;

import com.github.pagehelper.PageInfo;
import com.koron.bean.base.Response;
import com.koron.bean.system.staff.vo.EamUser;
import com.koron.common.core.annocation.CasUser;
import com.koron.sinoprobe.web.ledger.bean.entity.SpContract;
import com.koron.sinoprobe.web.ledger.bean.query.SpContractQuery;
import com.koron.sinoprobe.web.ledger.service.SpContractService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.koron.ebs.mybatis.ADOConnection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * @author twcao
 * @title: SpContractController
 * @projectName GDH_EAM_V2
 * @description: 专项台账-项目合同
 * @date 2021/12/616:51
 */
@Slf4j
@RestController
@RequestMapping("/sp/project/contract/")
@Api(tags = "专项台账-项目合同")
public class SpContractController {

    @Autowired
    private SpContractService contractService;

    @GetMapping("/selectOne")
    @ApiOperation("项目合同详情查询")
    @ApiImplicitParam(name = "id", value = "项目合同id", required = true)
    public Response<SpContract> selectOne(@CasUser @ApiIgnore EamUser user, @RequestParam String id) {
        SpContract detail = ADOConnection.runTask(user.getCurrDs(), contractService, "queryById", SpContract.class, id);
        return Response.ok("查询成功", detail);
    }

    @GetMapping("/queryList")
    @ApiOperation("项目合同分页查询， 未分页")
    public Response<PageInfo<SpContract>> queryList(@CasUser @ApiIgnore EamUser user, SpContractQuery query) {
        List<SpContract> list = ADOConnection.runTask(user.getCurrDs(), contractService, "queryList", List.class, query);
        return Response.ok("查询成功", new PageInfo<>(list));
    }

    @PostMapping("/saveOrUpdate")
    @ApiOperation("新增或修改项目合同")
    public Response<SpContract> saveOrUpdate(@CasUser @ApiIgnore EamUser user, @RequestBody SpContract detail) {
        detail = ADOConnection.runTask(user.getCurrDs(), contractService, "saveOrUpdate", SpContract.class, detail);
        return Response.ok("操作成功", detail);
    }

    @GetMapping("/deleteById")
    @ApiOperation("根据id删除项目合同")
    @ApiImplicitParam(name = "id", value = "项目合同id", required = true)
    public Response<String> deleteById(@CasUser @ApiIgnore EamUser user, @RequestParam String id) {
        ADOConnection.runTask(user.getCurrDs(), contractService, "deleteById", Boolean.class, id);
        return Response.ok("删除成功", id);
    }
}
